package com.fessc.develop.job;

import com.fessc.develop.entity.ccbvo.CCBBankCheckJsonVo;
import com.fessc.develop.handler.CCBBankCheckJsonPushHandler;
import com.fessc.develop.model.enums.EnumCheckType;
import com.fessc.develop.model.enums.EnumPushType;
import com.fessc.develop.model.enums.EnumTaskCode;
import com.fessc.develop.service.interfaces.ITPaymentService;
import com.fessc.develop.utils.BusiUtil;
import com.fessc.develop.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

@Slf4j
@Service
public class CCBBankCheckJsonJob extends ScheduleJob {
    @Resource
    private ITPaymentService paymentService;

    @Resource
    private CCBBankCheckJsonPushHandler ccbBankCheckJsonPushHandler;

    @Override
    public String execute() {
        //获取推送银行的结果集
        log.info("推送日终对账至建行处理");
        List<CCBBankCheckJsonVo> ccbBankCheckJsonVoList = new ArrayList<CCBBankCheckJsonVo>();
        try {
            CCBBankCheckJsonVo jsonVo = new CCBBankCheckJsonVo();
            log.info("推送日终对账至建行处理：" + Date.valueOf(DateUtil.getLastDayDate(DateUtil.getCurrentDateTime(), 1)));
            jsonVo.setType(EnumCheckType.PRE_PAYMENT_CHECK.toString());  //扣款
            jsonVo.setBatchNo(BusiUtil.getSerialNumber(getCCBBankId(), "", 5));
            jsonVo.setBankId(getCCBBankId());
            jsonVo.setChectDate(Date.valueOf(DateUtil.getLastDayDate(DateUtil.getCurrentDateTime(), 1)));  //对账时间
            ccbBankCheckJsonVoList.add(jsonVo);
            CCBBankCheckJsonVo refundVo = new CCBBankCheckJsonVo();
            refundVo.setType(EnumCheckType.REFUND_CHECK.toString());  //退款
            refundVo.setBatchNo(BusiUtil.getSerialNumber(getCCBBankId(), "", 5));
            refundVo.setBankId(getCCBBankId());
            refundVo.setChectDate(Date.valueOf(DateUtil.getLastDayDate(DateUtil.getCurrentDateTime(), 1)));  //对账时间
            ccbBankCheckJsonVoList.add(refundVo);
        } catch (Exception e) {
            log.info("获取对账日期失败：" + e.getMessage());
        }
        ccbBankCheckJsonPushHandler.ccbBankCheckJsonPush(ccbBankCheckJsonVoList, EnumPushType.CHECKING_PUSH.toString());
        return null;
    }

    @Override
    public String getTaskCode() {
        return EnumTaskCode.CCB_BANK_CHECK_PUSH.toString();
    }
}
